import java.util.Scanner;

/**
 * This program plays a game of TicTacToe.
 */
public class TicTacToePlayer {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char player = 'x';
		TicTacToe game = new TicTacToe();

		boolean done = false;
		while (!done) {
			System.out.println(game); // calls game.toString()
			System.out.println("Row for " + player + " (Q to exit): ");
			String input = in.next();

			if (input.equalsIgnoreCase("Q"))
				done = true;
			else {
				int row = Integer.parseInt(input);
				System.out.println("Column for " + player + ": ");
				int column = in.nextInt();

				game.set(row, column, player);

				if(game.getWinner()!=' ')
				{
					done=true;
					System.out.println("The winner is "+game.getWinner());
					System.out.println(game);
				}

				if (player == 'x')
					player = 'o';
				else
					player = 'x';

			}
		}
	}
}
